//
//  PartyDataViewController.m
//  UESTCPioneer
//
//  Created by Sway on 14-3-5.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import "PartyDataViewController.h"
#import "LeveyTabBarController.h"
#import "helper.h"
#import "TheoryViewController.h"
#import "PersonalViewController.h"
#import "OrganTableViewController.h"
#import "LearnTableViewController.h"
#import "QAViewController.h"
#import "ProcessTableViewController.h"
#import "MLearnTableViewController.h"
#import "VedioDownloadViewController.h"
#import "PartyClassFeelingViewController.h"

/*************/
#import "DevelopPartyerController.h"
#import "PartyerShowController.h"
#import "PartyKnowledgeController.h"
#import "PartyCleanCurtureController.h"
#import "PartyClassResourceController.h"
#import "PartyVirtualTestController.h"
/*************/
@interface PartyDataViewController ()
@property (nonatomic,strong) NSDictionary * dic;
@property (nonatomic,strong) NSArray *titleArray;

/*最新修改*/
@property (nonatomic,strong) UIScrollView * scrollView;
/**/
@end

@implementation PartyDataViewController

- (NSDictionary *) dic{
    if (!_dic) {
////        _dic = @{@"中央精神": @"censpi.png",
//                 @"党的知识":@"knowledge.png",
//                 @"党的理论":@"theory.png",
//                 @"党校学习":@"learn.png",
//                 @"入党流程":@"process.png",
//                 @"组织架构":@"organ.png",
//                 @"办事指南":@"guide.png",
//                 @"Q&A":@"QA.png",
//                 @"专业学习":@"spcail.png"};
        
//        _dic = @{@"党课视频":@"partyvedio.png",@"党课资料":@"learn.png",@"党课心得":@"partyreport.png",@"中央精神": @"censpi.png",@"党的知识":@"knowledge.png",@"党的理论":@"theory.png",@"入党流程":@"process.png",@"组织架构":@"organ.png",@"办事指南":@"guide.png",@"专业学习":@"spcail.png",@"Q&A":@"QA.png",@"新生指南":@"compass.png"};
   
    _dic = @{
             @"中央精神": @"censpi.png",
             @"党的理论":@"theory.png",
             @"党识竞答":@"knowledge.png",
             @"党课资料":@"organ.png",
             @"党课视频":@"partyvedio.png",
             @"党课模考":@"QA.png",
             @"入党流程":@"process.png",
             @"廉政文化":@"learn.png",
             @"党员风采":@"spcail.png",
             };
    }
    return _dic;
}

- (NSArray *)titleArray{
    if (!_titleArray) {
        _titleArray = @[
                        @"中央精神",
                        @"党的理论",
                        @"党识竞答",
                        @"党课资料",
                        @"党课视频",
                        @"党课模考",
                        @"入党流程",
                        @"廉政文化",
                        @"党员风采"
                        ];
    }
    return _titleArray;
}

- (NSMutableArray *)buttons{
    if (!_buttons) {
        _buttons = [[NSMutableArray alloc] init];
        
        for (int i = 0; i < 3; i ++) {
            for (int j = 0;  j < 3; j++) {
                UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(j*100+15, i*110+15, 90, 100)];
                [btn.layer setBorderWidth:1.0f];
                [btn.layer setBorderColor:[UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.8].CGColor];
                UIImage * image = [helper getCustomImage:[UIImage imageNamed:self.dic[self.titleArray[i*3+j]]] insets:UIEdgeInsetsMake(20, 30, 63, 60)];
                [btn setBackgroundImage:image forState:UIControlStateNormal];
                [btn setBackgroundColor:[UIColor whiteColor]];
                [btn setTitleEdgeInsets:UIEdgeInsetsMake(60, 20, 0, 20)];
                btn.titleLabel.font = [UIFont systemFontOfSize:12.0];
                [btn setTitle:self.titleArray[i*3+j] forState:UIControlStateNormal];
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(aButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
                [_buttons addObject:btn];
            }
        }
    }
    return _buttons;
}

-(void) aButtonClicked:(UIButton *)sender{
    UIViewController * viewController ;
    NSMutableDictionary * requestDic = [[NSMutableDictionary alloc ] initWithDictionary: @{@"type":@"getMajorFile",@"dangType":@"1",@"page":@"1",@"fileType":@"video"}];
    switch ([self.buttons indexOfObject:sender]) {
        case 0:
            /*@"中央精神",*/
            viewController = [[TheoryViewController alloc] initWithTitle:self.titleArray[0] RequestData:@{@"type": @"studySpirit",@"page":@"1"} EntityName:@"PartyDataKnowledgeEntity" Mapping:[Mapping PartyDataSpiritEntityMapping]];
            break;
        case 1:
            /*党的理论*/
            viewController = [[TheoryViewController alloc] initWithTitle:self.titleArray[1] RequestData:@{@"type":@"studyTheory",@"page":@"1"} EntityName:@"PartyDataTheoryEntity" Mapping:[Mapping PartyDataSpiritEntityMapping]];
            break;
        case 2:
            /*党史竞赛*/
            viewController = [[PartyKnowledgeController alloc] init];
            break;
        case 3:
            /*党课资料*/
            viewController = [[PartyClassResourceController alloc] init];
            break;
        case 4:
            /*党课视频*/
            viewController =[[VedioDownLoadViewController alloc] initWithRequestData:requestDic entityName:@"PartyVedioDownloadEntity" Mapping:[Mapping PartyVedioDownloadEntityMapping]];
            break;
        case 5:
            /*党课模考*/
            viewController = [[PartyVirtualTestController alloc] init];
            break;
        case 6:
            /*发展党员*/
            viewController = [[DevelopPartyerController alloc] init];
            break;
        case 7:
            /*廉政文化*/
            viewController = [[PartyCleanCurtureController alloc] init];
            break;
        case 8:
            /*党员风采*/
            viewController = [[PartyerShowController alloc] initWithRequestData:@{@"type":@"excellentMember",@"page":@"1",@"idMin":@"1"} entityName:@"PartyerShowEntity"  Mapping:[Mapping PartyerShowEntityMapping]];
            break;
        default:
            break;
    }
    [self.leveyTabBarController.navigationController pushViewController:viewController animated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.leveyTabBarController.navigationItem.rightBarButtonItem = nil;
    
    [self.view setUserInteractionEnabled:YES];
    /*modify for 党课心得*/
    UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)];
    scrollView.contentSize=CGSizeMake(self.view.frame.size.width,self.view.frame.size.width);
    scrollView.scrollEnabled = YES;
    /**/

    self.scrollView = scrollView;
    for (UIButton * btn in self.buttons) {
        [scrollView addSubview:btn];
    }
    [self.view addSubview:scrollView];
    
    //    for (UIButton * btn in self.buttons) {
    //        [self.view addSubview:btn];
    //    }
    /*end*/
    [self.view setBackgroundColor:ViewControllerBackgroundColor];
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [self.leveyTabBarController.navigationItem setTitle:@"微党课"];
    [self.leveyTabBarController.navigationItem setLeftBarButtonItem:nil];
    [self.leveyTabBarController.navigationItem  setRightBarButtonItem:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
